<template>
    <van-sticky>
        <van-nav-bar title="分类" left-arrow @click-left="onClickLeft" />
    </van-sticky>
    <div class="box">
        <div class="left">
            <van-sidebar v-model="active">
                <van-sidebar-item v-for="item in fenleiList" :title="item.cat_name" />
            </van-sidebar>

        </div>
        <div class="right">
            <van-grid :column-num="3" v-for="item in fenleiList[active]?.children">
                <van-grid-item  v-for="value in item.children" :key="value.cat_id" :icon="value.cat_icon" 
                :text="value.cat_name"  @click="pushdian(value.cat_id)"/>
            </van-grid>
        </div>
    </div>
</template>

<script setup>
import axios from "axios";
import { ref } from "vue";
import { useRouter } from 'vue-router'
const router = useRouter()
const active =ref(0)
const onClickLeft = () => history.back();

// import {useFenleiStore} from '../../store'
// import {storeToRefs} from 'pinia'
// const {fenleiList}=useFenleiStore();
// const {FENLEI}=storeToRefs(useFenleiStore());
// FENLEI()

const fenleiList=ref([]);
axios.get("https://api-hmugo-web.itheima.net/api/public/v1/categories").then(res=>{
    fenleiList.value=res.data.message
})

const pushdian=(cid)=>{
    router.push({
        path:"/goods",
        query:{
            cid
        }
    })
}
</script>

<style lang="scss" scoped>
.box {
    display: flex;
}

.left {
    width: 100px;
}

.right {
    flex: 1;
}
</style>